<template>
  <h1>El-表格组件</h1>
  <el-table :data="tableData" style="width: 100%">
    <el-table-column prop="date" label="日期" width="180" />
    <el-table-column prop="name" label="姓名" width="180" />
    <el-table-column prop="address" label="地址" />
  </el-table>

  <el-table :data="arr" style="width:600px;margin: 0 auto;">
    <el-table-column label="序号" type="index" width="80" align="center"></el-table-column>
    <el-table-column label="姓名" prop="name" align="center"></el-table-column>
    <el-table-column label="薪资" prop="salary" align="center"></el-table-column>
    <el-table-column label="职位" prop="job" align="center"></el-table-column>
    <el-table-column label="操作" align="center">
      <!-- template表示自定义列模板,如果想要在表格中加入其他的组件,必须加template标签包裹!-->
      <!-- #default代表插槽slot 能够允许我们将其它组件嵌入表格中  -->
      <!-- scope对象用来保存表格的上下文数据
      scope.row就代表当前行对象,比如当前是用户表,那么scope.row就代表了本行的这个用户对象
      scope.$index代表当前行对象的索引值,从0开始,注意与上面的序号index(从1开始)区分! -->
      <template #default="scope">
        <el-button type="danger" @click="del(scope.row,scope.$index)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>
<script setup>
import {ref} from "vue";
//定义数组用来模拟从后端查回来的用户数据
const arr = ref([
  {name: '张三', salary: 3000, job:'饲养员'},
  {name: '李四', salary: 4000, job:'护林员'},
  {name: '王五', salary: 5000, job:'销售员'},
  {name: '赵六', salary: 6000, job:'程序员'}
]);
//定义删除员工的方法
const del = (emp,index)=>{
  if(confirm('您确认要删除'+emp.name+'吗?')){
    arr.value.splice(index,1);
  }
}


const tableData = [
  {
    date: '2016-05-03',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-02',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-04',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-01',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
]
</script>

<style scoped>

</style>